/*
 * @lc app=leetcode.cn id=119 lang=cpp
 *
 * [119] 杨辉三角 II
 */

// @lc code=start
class Solution {
public:
    vector<int> getRow(int rowIndex) {
        vector<int> ans[2];
        ans[0].push_back(1);
        ans[1].push_back(1);
        ans[1].push_back(1);

        for(int i = 2; i <= rowIndex; i++)
        {
            int flag = i % 2;
            ans[flag].clear();
            ans[flag].push_back(1);
            for(int j = 1; j < i; j++)
            {
                ans[flag].push_back(ans[(flag + 1) % 2][j - 1] + ans[(flag + 1) % 2][j]);

            }
            ans[flag].push_back(1);            
        }
        return ans[rowIndex % 2];
    }
};
// @lc code=end

